import Obj from "../core/Obj";
import UnmodifiableCollection from "../core/UnmodifiableCollection";
import List from "./List";
import UnsupportedOperationException from "../exceptions/UnsupportedOperationException";
import Comparator from "../utils/Comparator";

export default class UnmodifiableList<E> extends UnmodifiableCollection<E> implements List<E> {
  private readonly list: List<E>;

  public constructor(list: List<E>) {
    super(list);
    this.list = list;
  }

  add(e: E): boolean {
    throw new UnsupportedOperationException(UnmodifiableList, this.add);
  }

  addByIndex(index: number, e: E): void {
    throw new UnsupportedOperationException(UnmodifiableList, this.addByIndex);
  }

  capacity(): number {
    return this.list.capacity();
  }

  equals(b: Obj): boolean {
    return this.list.equals(b);
  }

  get(index: number): E {
    return this.list.get(index);
  }

  hashCode(): number {
    return this.list.hashCode();
  }

  indexOf(e: E): number {
    return this.list.indexOf(e);
  }

  lastIndexOf(e: E): number {
    return this.list.lastIndexOf(e);
  }

  remove(e: E): boolean {
    throw new UnsupportedOperationException(UnmodifiableList, this.remove);
  }

  removeByIndex(index: number): E {
    throw new UnsupportedOperationException(UnmodifiableList, this.removeByIndex);
  }

  removeIf(filter: (e: E) => boolean): boolean {
    throw new UnsupportedOperationException(UnmodifiableList, this.removeIf);
  }

  set(index: number, e: E): E {
    throw new UnsupportedOperationException(UnmodifiableList, this.set);
  }

  sort(comparator?: Comparator): void {
    throw new UnsupportedOperationException(UnmodifiableList, this.sort);
  }

  subList(fromIndex: number, endIndex: number): List<E> {
    return new UnmodifiableList(this.list.subList(fromIndex, endIndex));
  }
}
